package com.ssm.util;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * Created by Lenovo on 2019/11/8.
 */
public class ProxyFactory {
    final static MyAspect ma=new MyAspect();
    public static Object CreateProxy(final Object us){
        Object obj= Proxy.newProxyInstance(us.getClass().getClassLoader(), us.getClass().getInterfaces(),
                new InvocationHandler() {
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                         ma.before();
                         Object obj1=method.invoke(us,args);
                         ma.after();
                        return obj1;
                    }
                });
        return obj;
    }
}
